package com.gomtel.smartdevice.ui.holder;

import android.content.Context;
import android.util.Log;
import android.util.Pair;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chs.easychartwidget.entity.ChartEntity;
import com.gomtel.smartdevice.widget.LineChartNew;
import com.gomtel.smartdevice.R;
import com.gomtel.smartdevice.base.BasicHolder;
import com.gomtel.smartdevice.bean.PulseConditionBeanPlus;
import com.gomtel.smartdevice.global.WatchApplication;
import com.gomtel.smartdevice.moudle.db.entity.PulseConditionBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/7/19 0019.
 */

public class PulseConditionHolder extends BasicHolder<Object> {

    private Context context;
    private Pair pulseConditionBean;
    private ImageView type;
    private TextView fitnessType;
    private TextView open_about;
    private LineChartNew lineNew;
    private ArrayList<PulseConditionBeanPlus> second;

    public PulseConditionHolder(Context context) {
        this.context = context;
    }

    @Override
    public View initHolderView() {
        View view = View.inflate(WatchApplication.getInstance(), R.layout.item_pluse_condition, null);
        type = view.findViewById(R.id.type);
        fitnessType = view.findViewById(R.id.fitnessType);
        open_about = view.findViewById(R.id.open_about);
        lineNew = view.findViewById(R.id.lineNew);
        return view;
    }

    @Override
    public void bindData(Object data) {
        pulseConditionBean = (Pair) data;
        second = (ArrayList<PulseConditionBeanPlus>) ((Pair) data).second;
        setType((int) pulseConditionBean.first);
    }

    private void setType(int type_mai) {
        switch (type_mai) {
            case 0:
                type.setImageResource(R.mipmap.xinmai);
                break;
            case 1:
                type.setImageResource(R.mipmap.ganmai);
                break;
            case 2:
                type.setImageResource(R.mipmap.shenmai);
                break;
        }
        List<PulseConditionBean> getplus = getplus(type_mai);
        Log.e(TAG, getplus.toString());
        List<ChartEntity> chartEntities = new ArrayList<>();
        for (PulseConditionBean conditionBean : getplus) {
            ChartEntity chartEntity;
            String maili = conditionBean.getMaili();
            switch (maili) {
                case "弱脉":
                    chartEntity = new ChartEntity(conditionBean.getDay(), 200f, "#129BCB");
                    break;
                case "缓脉":
                    chartEntity = new ChartEntity(conditionBean.getDay(), 400f, "#108344");
                    break;
                case "玄脉":
                    chartEntity = new ChartEntity(conditionBean.getDay(), 600f, "#FFE400");
                    break;
                case "紧脉":
                    chartEntity = new ChartEntity(conditionBean.getDay(), 800f, "#FBA71C");
                    break;
                case "实脉":
                    chartEntity = new ChartEntity(conditionBean.getDay(), 1000f, "#E10D01");
                    break;
                default:
                    chartEntity = new ChartEntity(conditionBean.getDay(), 1000f, "#E40313");
                    break;
            }
            chartEntities.add(chartEntity);
        }
        lineNew.setData(chartEntities,getplus);
    }

    private List<PulseConditionBean> getplus(int type) {
        List<PulseConditionBean> pulseConditionBeanPluses = new ArrayList<>();
        for (PulseConditionBeanPlus pulseConditionBeanPlus : second) {
            PulseConditionBean ganMai = pulseConditionBeanPlus.getGanMai();
            PulseConditionBean shenMai = pulseConditionBeanPlus.getShenMai();
            PulseConditionBean xinMai = pulseConditionBeanPlus.getXinMai();
            switch (type) {
                case 0:
                    if (ganMai.getType().equals("xin")) {
                        pulseConditionBeanPluses.add(ganMai);
                    }
                    if (shenMai.getType().equals("xin")) {
                        pulseConditionBeanPluses.add(shenMai);
                    }
                    if (xinMai.getType().equals("xin")) {
                        pulseConditionBeanPluses.add(xinMai);
                    }
                    break;
                case 1:
                    if (ganMai.getType().equals("gan")) {
                        pulseConditionBeanPluses.add(ganMai);
                    }
                    if (shenMai.getType().equals("gan")) {
                        pulseConditionBeanPluses.add(shenMai);
                    }
                    if (xinMai.getType().equals("gan")) {
                        pulseConditionBeanPluses.add(xinMai);
                    }
                    break;
                case 2:
                    if (ganMai.getType().equals("shen")) {
                        pulseConditionBeanPluses.add(ganMai);
                    }
                    if (shenMai.getType().equals("shen")) {
                        pulseConditionBeanPluses.add(shenMai);
                    }
                    if (xinMai.getType().equals("shen")) {
                        pulseConditionBeanPluses.add(xinMai);
                    }
                    break;
            }
        }
        return pulseConditionBeanPluses;
    }
}
